package com.walkline.weibo.dao;

import java.util.Vector;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.util.Function;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.GroupList;
import com.walkline.weibo.inf.GroupListWrapper;

public class WeiboGroupListWrapper extends WeiboObject implements GroupListWrapper
{
	private int _total_number = 0;
	private Vector _groupLists = new Vector();

	public WeiboGroupListWrapper(WeiboSDK weibo, JSONObject jsonObject) throws WeiboException
	{
		super(weibo, jsonObject);

		JSONObject groupListWrapper = jsonObject;
		if (groupListWrapper != null)
		{
			_total_number = groupListWrapper.optInt("total_number");

			JSONArray groupLists = groupListWrapper.optJSONArray("lists");
			if (groupLists != null)
			{
				JSONObject groupListObject;
				GroupList groupList;

				for (int i=0; i<groupLists.length(); i++)
				{
					try {
						groupListObject = (JSONObject) groupLists.get(i);

						groupList = new WeiboGroupList(weibo, groupListObject);
						if (groupList != null) {_groupLists.addElement(groupList);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public Vector getGroupLists() {return _groupLists;}

	public int getTotalNumber() {return _total_number;}
}